<?php

namespace app\common\model;

class ConfigCate extends \think\Model
{
    protected $name = 'config_cate';
    /**
     * 删除分组时检查是否有配置项
     */
    public static function OnBeforeDelete($model)
    {
        if (Config::where(['cate_id' => $model['id']])->find()) {
            throw new \Exception('当前分组存在配置项,请先删除或转移到其他分组');
        }
    }

    public function config()
    {
        return $this->hasMany(Config::class, 'cate_id', 'id')->order('sort desc');
    }
}
